﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using mshtml;
using HtmlAgilityPack;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class MyHtmlParser
    {
        public static List<string> GetPostsNumberOnPage(string html)
        {
            List<string> postsList = new List<string>();
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(html);
            HtmlNodeCollection c = doc.DocumentNode.SelectNodes("//div[@class='alt1' and contains(@id,'td_post_')]");
            HtmlNodeCollection memberInfo;

            foreach (HtmlNode n in c)
            {
                HtmlAttributeCollection atrCol = n.Attributes;
                foreach (HtmlAttribute item in atrCol)
                {                    
                    if (item.Name == "id")
                    {
                        string post = item.Value.Replace("td_post_", "").Trim();
                        postsList.Add(post);
                            MessageBox.Show(postsList[postsList.Count-1]);
                    }
                }   
            }

            c = doc.DocumentNode.SelectNodes("//div[@class='alt1' and contains(@id,'td_post_')]");

            return postsList;
        }

        public static int GetLastPageForTheme(string html)
        {
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(html);            
            HtmlNodeCollection c = doc.DocumentNode.SelectNodes("//a[contains(@href,'showthread.php?t=')]");
            //  //BBB[normalize-space(@name)='bbb']
            //HtmlNodeCollection c = doc.DocumentNode.SelectNodes("//a[text() = 'Последняя страница']");
            //HtmlAttributeCollection atrCol = c[0].Attributes;
            //string [] colStr = atrCol["title"].Value.Split(' ');
            //int number =Convert.ToInt32(colStr[colStr.Length - 1].Replace(",",""));
            //MessageBox.Show(number.ToString());            
            return 1;
        }
    }
}
